package Day05;

public class Homework02 {
    public static void main(String[] args) {
        // 利用for循环计算：求数字1到100之内，所有偶数的和，并输出
        int sum = 0;
        for (int i = 2; i <= 100; i += 2) {
            sum += 1;
        }
        System.out.println("sum=" + sum);


        //利用for循环计算：求8的阶乘，并输出
        int num = 1;
        for (int a = 1; a <= 8; a++) {
            num *= a;
        }
        System.out.println("num=" + num);

        //定义数组，包含10个元素，随机生成数据(范围自拟)，查找最大值和最小值，并输出
        int[] a = new int[10];
        for (int b = 0; b < a.length; b++) {
            a[b] = (int) (Math.random() * 100);
            System.out.println(a[b]);
        }
        int max = a[0];
        int min = a[0];
        for (int c = 1; c < a.length; c++) {
            if (a[c] > max) {
                max = a[c];
            }
            if (a[c] < min) {
                min = a[c];
            }
        }
        System.out.println("最大值为：" + max + "最小值为：" + min);


        //利用for循环计算：打印字符*组成的等腰三角形
        for (int o = 1; o <= 7; o++) {
            for (int i = 1; i <= 2 * o - 1; i++) {
                System.out.print("*");
            }
            System.out.println();
        }


    }
}
